﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework.Input;
using Utils.MathUtilitys;

namespace Utils.StageManagement
{
    public class DTimeManager
    {
        const int baseMultiplier = 5;
        float[] dTimeMultipliers = { 0.05f, 0.1f, 0.2f, 0.35f, 0.5f, 1f, 1.5f, 2f, 3f };

        protected float dTimeMultiplier = 1;
        protected bool keyDecPressed;
        protected bool keyIncPressed;
        protected bool keyResetPressed;
        protected int currentMultiplier = baseMultiplier;

        public float DTimeMultiplier { get { return dTimeMultiplier; } }

        [Conditional("DEBUG")]
        public virtual void UpdateDTimeMultiplier()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.PageDown) && !keyDecPressed)
            {
                currentMultiplier = MathUtils.Cap(currentMultiplier - 1, 0, dTimeMultipliers.Count() - 1);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.PageUp) && !keyIncPressed)
            {
                currentMultiplier = MathUtils.Cap(currentMultiplier + 1, 0, dTimeMultipliers.Count() - 1);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.End) && !keyResetPressed)
            {
                currentMultiplier = baseMultiplier;
            }

            dTimeMultiplier = dTimeMultipliers[currentMultiplier];

            keyDecPressed = Keyboard.GetState().IsKeyDown(Keys.PageDown);
            keyIncPressed = Keyboard.GetState().IsKeyDown(Keys.PageUp);
            keyResetPressed = Keyboard.GetState().IsKeyDown(Keys.End);
        }
    }
}
